home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Add-Ons / BBEdit / MacBob 1.0ß2 / Examples / HexDump2.bob < prev    next >
Encoding:
Text File  |  1995-12-06  |  850 b   |  50 lines  |  [TEXT/R*ch]

  1. /***
  2.  *
  3.  *    HexDump2.bob - Another example program to dump any file in
  4.  *                   hexidecimal.  This version produces less garbage
  5.  *                   but is slightly more obscure.
  6.  *
  7.  ***/
  8.  
  9. main ()
  10. {
  11. //    if (getfile("TEXT"))
  12.     if (getfile())
  13.         ProcessFile();
  14.     else
  15.         print("*** ERROR: Couldn't get file ***\n");
  16. }
  17.  
  18.  
  19. HexByte (byte, str, index ; n)
  20. {
  21.     n = (byte >> 4) & 15;
  22.     str[index++] = (n <= 9 ? '0' : 'A' - 10) + n;
  23.     n = byte & 15;
  24.     str[index] = (n <= 9 ? '0' : 'A' - 10) + n;
  25.     return str;
  26. }
  27.  
  28.  
  29. ProcessFile ( ; c, i, line, offset)
  30. {
  31.     line = offset = "000000: ";
  32.     i = 0;
  33.  
  34.     while ((c = getc(stdin)) != -1) {
  35.         line += HexByte(c, " ??", 1);
  36.         ++i;
  37.         if ((i & 15) == 0) {
  38.             print(line, "\n");
  39.             line = HexByte(i >> 16,
  40.                         HexByte(i >> 8,
  41.                             HexByte(i, offset, 4),
  42.                             2),
  43.                         0);
  44.         }
  45.     }
  46.     if (sizeof(line) != 0)
  47.         print(line, "\n");
  48.     print("<END>\n");
  49. }
  50.